package cz.zcu.fav.ratdroid.activity.calendar.provider;

import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

import android.content.Context;
import android.graphics.drawable.LayerDrawable;
import cz.zcu.fav.ratdroid.R;
import cz.zcu.fav.ratdroid.activity.calendar.day.BlockView;
import cz.zcu.fav.ratdroid.bean.Occupations;
import cz.zcu.fav.ratdroid.bean.Period;
import cz.zcu.fav.ratdroid.bean.Reservations;
import cz.zcu.fav.ratdroid.service.IRestListener;
import cz.zcu.fav.ratdroid.service.RestService;
import cz.zcu.fav.ratdroid.service.RestTask;
import cz.zcu.fav.ratdroid.bean.Object;
public class ObjectDataProvider implements ICalendarDataProvider
{
	private static final long serialVersionUID = 1838969870539635659L;
	private Object object;
	private Integer userId;

	public ObjectDataProvider(Object object, Integer userId)
	{
		this.object = object;
		this.userId = userId;
	}

	public RestTask<Occupations> getDatesOccupation(Context context,
			int month, int year, IRestListener<Occupations> listener)
	{

		return RestService.getInstance().getDatesObjectOccupation(context,
				month, year, listener, object.getId());
	}

	public RestTask<Reservations> getReservations(Context context,
			LocalDateTime since, LocalDateTime to,
			IRestListener<Reservations> listener)
	{
		return RestService.getInstance().getReservationsByObject(object.getId(),
				context, since, to, listener);
	}

	public BlockView getBlock(Context context, String title, 
			int column, Period period, LocalDate selectedDate)
	{
		return new BlockView(context, title, column, period, selectedDate)
		{
			@Override
			protected int evaluateColor(LayerDrawable buttonDrawable,
					Period period)
			{
				if (!period.getReservation().getUserId().equals(userId))
				{
					return getResources().getColor(R.color.block_color_grey);
				} else
				{
					return getResources().getColor(R.color.block_color_green);
				}
			}
		};
	}

	public Object provideObject()
	{
		return object;
	}

}
